﻿using System;

namespace BizElements.Core
{
    /// <summary>Provides basic entity field validation, i.e. checks constraints defined in <see cref="IDbTable"/> object.</summary>
    public interface IEntityValidator
    {
        /// <summary>GEts or sets entity to validated.</summary>
        IEntity ValidatedEntity { get; set; }

        /// <summary>
        /// Validates all fields of an entity. Returns all encountered errors.
        /// </summary>
        /// <returns>Array of FieldError objects that describe all encountered errors. Empty array if there are no errors.</returns>
        FieldError[] ValidateAllFields();

        /// <summary>
        /// Returns a value which indicates whether all fields of an entity contain valid values. 
        /// </summary>
        /// <returns>True if all fields are valid; false otherwise.</returns>
        bool IsValidEntity();

        /// <summary>
        /// Validates specified field.
        /// </summary>
        /// <remarks>Checks whether the value contained in the given field obeys basic constraints 
        /// (nullability, min/max value etc). Returns <see cref="FieldErrorCode"/> that indicates 
        /// the type of error encountered.</remarks>
        /// <param name="field">Field mapped in this entity.</param>
        /// <returns>Error code that indicates the type of encountered error.</returns>
        FieldErrorCode ValidateField(IDbColumn field);

        /// <summary>
        /// Returns a value which indicates whether the specifified is valid.
        /// Checks whether the value contained in the given field obeys basic constraints (nullability, min/max value etc).
        /// </summary>
        /// <param name="field">Field mapped in this entity.</param>
        /// <returns>True if the field is valid; false otherwise.</returns>
        bool IsValidField(IDbColumn field);
    }
}
